﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Corsat.Library.DataManager;
using Corsat.Library.Logic;

namespace Corsat.Web._2013.Administration
{
    public partial class UpdateStudentData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Library.Item> TeleTypes = Corsat.Library.DataManager.Main.GetAllItemsByCategory(Library.DataManager.Category.TelephoneTypes);
            ddlTelephone1.DataSource = TeleTypes;
            ddlTelephone1.DataTextField = "Value";
            ddlTelephone1.DataValueField = "Id";
            ddlTelephone1.DataBind();
            ddlTelephone2.DataSource = TeleTypes;
            ddlTelephone2.DataTextField = "Value";
            ddlTelephone2.DataValueField = "Id";
            ddlTelephone2.DataBind();
            ddlTelephone3.DataSource = TeleTypes;
            ddlTelephone3.DataTextField = "Value";
            ddlTelephone3.DataValueField = "Id";
            ddlTelephone3.DataBind();
        }

        [WebMethod]
        public static object GetData(string searchText)
        {
            if (!string.IsNullOrWhiteSpace(searchText) )
            {
                Account account = Main.GetAccountBySSN(searchText);

                if (account != null)
                {
                    return new { account.AccountId, account.CorsatId, account.ArabicName, account.Email, account.SSN, account.Telephones };
                }
            }

            var response = new { error="notfound" };
            return response;
        }

        [WebMethod]
        public static bool Save(Account account)
        {
            return Main.UpdateAccountData(account);
        }
    }
}